<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button id="start">开始</button>
    <button id="end">结束</button>

    <script>
      var timer;
      document.getElementById('start').onclick = function () {
        timer = setInterval(function () {
          console.log('aini');
        }, 1000);
      };
      document.getElementById('end').onclick = function () {
        clearInterval(timer);
      };
    </script>
  </body>
</html>
